package org.springblade.upgrade.record.controller;

import org.springblade.upgrade.record.model.UpgradeRecordBean;
import org.springblade.upgrade.record.service.IUpgradeRecordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 控制器
 *
 * @author qp
 */
@Slf4j
@RestController
@RequestMapping("/record")
public class UpgradeRecordController extends BladeController {

	@Resource
	private IUpgradeRecordService recordService;


	/**
	 * 删除接口
	 */
	@PostMapping("/remove")
	public R<String> remove(UpgradeRecordBean param) {
		try {
            this.recordService.deleteData(param);
            return R.success("删除成功");
		} catch (Exception ex) {
            log.error("删除异常" + ex.getMessage(), ex);
        	return R.fail(ex.getMessage());
		}
	}

	/**
	 * 查看详情接口
	 */
	@GetMapping("/detail")
	public R<UpgradeRecordBean> detail(UpgradeRecordBean param) {
		try{
			UpgradeRecordBean detail = this.recordService.findBySpec(param);
			return R.data(detail);
		} catch (Exception ex) {
			log.error("查询异常" + ex.getMessage(), ex);
			return R.fail(ex.getMessage());
		}
	}

	/**
	 * 查询分页
	 */
	@GetMapping("/page")
	public R<IPage<UpgradeRecordBean>> list(UpgradeRecordBean param, Query query) {
		try{
			IPage<UpgradeRecordBean> page = this.recordService.findPageBySpec(Condition.getPage(query), param);
			return R.data(page);
		} catch (Exception ex) {
			log.error("查询异常" + ex.getMessage(), ex);
			return R.fail(ex.getMessage());
		}
	}

}

